package com.aboo.design.prototype;

/*
 * @description
 * @author Yata.Niko
 * @version 1.0
 * @date 2024/1/31
 */
public class PrototypePattern {

    public static void main(String[] args) {
        PrototypeMoney money1 = new PrototypeMoney("人民币", 100);
        PrototypeMoney money2 = money1.clone();
        money2.setName("美元");
        money2.setAmount(1000);

        System.out.println(money1);
        System.out.println(money2);
    }
}

class PrototypeMoney implements Cloneable {

    private String name;
    private Integer amount;

    public PrototypeMoney(String name, Integer amount) {
        this.name = name;
        this.amount = amount;
    }

    @Override
    protected PrototypeMoney clone() {
        try {
            return (PrototypeMoney) super.clone();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    @Override
    public String toString() {
        return "PrototypeMoney{" +
                "name='" + name + '\'' +
                ", amount=" + amount +
                '}';
    }
}